package cn.thread;

public class RunnableTest002 implements Runnable{
    private int tekit=6;
    public static void main(String args[]){
        //一份资源。原理：初始化tekit等于6，然后在对象中的同一个位置执行tekit--
        RunnableTest002 r=new RunnableTest002();
        //多个代理
        new Thread(r,"黄牛001").start();
        new Thread(r,"黄牛002").start();
        new Thread(r,"黄牛003").start();
    }

    @Override
    public void run() {
        while (tekit>0){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"卖掉的票:"+tekit--);
        }
    }
}
